package com.park.web.controller;

import com.github.pagehelper.PageInfo;
import com.park.web.base.baseOperation.BaseController;
import com.park.web.core.wrapper.WrapMapper;
import com.park.web.core.wrapper.Wrapper;
import com.park.web.model.domain.basSystemUser;
import com.park.web.md5.*;
import com.park.web.model.dto.basSystemUserDto;
import com.park.web.service.basSystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(value = "WEB - BasSystemUserController", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@RequestMapping(value = "basSystemUser", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class BasSystemUserController extends BaseController {

    @Autowired
    basSystemUserService ibasSystemUserService;

    @PostMapping("/login")
    @ApiOperation(value = "用户登录", notes = "用户登录")
    public Wrapper Login(@RequestBody basSystemUserDto entity) {
        entity.setPwd(Md5Util.md5decode(entity.getPwd()));
        basSystemUser result = ibasSystemUserService.UserLogin(entity);
        if (result == null) {
            return WrapMapper.error("账号密码不正确");
        } else {
            return WrapMapper.ok(result);
        }
    }

    @PostMapping("/queryWithPage")
    @ApiOperation(value = "查询所有信息", notes = "查询所有信息")
    public Wrapper<PageInfo<basSystemUser>> queryWithPage(@RequestBody basSystemUserDto entity) {
        var list = ibasSystemUserService.queryWithPage(entity);
        return WrapMapper.ok(list);
    }
}